import java.util.*;

public class Solution {

    public int[] distributeCandies(int candies, int num_people) {
        int num = (int) Math.floor(-0.5 + Math.sqrt(2 * candies + 0.25));
        int[] arr = new int[num_people];
        int rows = num / num_people;
        for (int i = 1; i <= num_people; i++) {
            arr[i - 1] = rows * i + (rows - 1) * rows * num_people / 2;
        }
        int k;
        for (k = 0; k < num % num_people; k++) {
            arr[k] += rows * num_people + k + 1;
        }
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        arr[k] += candies - sum;
        return arr;
    }

    public static void main(String[] args) {
        int[] arr = new Solution().distributeCandies(60, 4);
        System.out.println(Arrays.toString(arr));
    }
}